package org.suk.dp.service;

import org.suk.dp.LotteryResult;
import org.suk.dp.event.EventManager;
import org.suk.dp.event.listener.MQEventListener;
import org.suk.dp.event.listener.MessageEventListener;
/**
 * @description: 抽象摇奖服务
 * @Date : 2020/12/30 10:46 AM
 * @Author : 石冬冬-Seig Heil
 */
public abstract class AbstractLotteryService {

    private EventManager eventManager;

    public AbstractLotteryService() {
        eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.Message);
        eventManager.register(EventManager.EventType.MQ, new MQEventListener());
        eventManager.register(EventManager.EventType.Message, new MessageEventListener());
    }

    public LotteryResult draw(String uId) {
        LotteryResult lotteryResult = doDraw(uId);
        // 需要什么通知就给调用什么方法
        eventManager.notify(EventManager.EventType.MQ, lotteryResult);
        eventManager.notify(EventManager.EventType.Message, lotteryResult);
        return lotteryResult;
    }

    protected abstract LotteryResult doDraw(String uId);

}
